package mybatis.share;

import java.io.IOException;
import java.io.InputStream;

import mybatis.share.mapper.PersonMapper;
import mybatis.share.vo.Person;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class Main {
	public static void main(String[] args) {
		String resource = "mybatis-config.xml";
		InputStream inputStream = null;
		try {
			inputStream = Resources.getResourceAsStream(resource);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		
		SqlSession sqlSession = sqlSessionFactory.openSession();
		
		PersonMapper pm =  sqlSession.getMapper(PersonMapper.class);
		
		
		Person p = new Person();
		p.setName("test");
		p.setDept("testa");
		p.setNum("1380013800");
		int i = pm.insert(p);
		System.out.println("插入的条数：" + i);
		System.out.println(p);
		
		p.setName("devp");
		p.setDept("devpa");
		p.setNum("10086");
		i = pm.update(p);
		System.out.println("修改的条数：" + i);
		
		System.out.println(pm.list());
		
		i = pm.delete(p);
		System.out.println("删除的条数："+i);
		
		System.out.println(pm.list());
		
	}
}
